﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for CouponDAL
/// </summary>
public class CouponDAL
{
    DataAccess db;
	public CouponDAL()
	{
        db = new DataAccess();
    }
    public int InsertUpdateCoupon(Coupon cp) 
    {
        SqlParameter[] paralist = new SqlParameter[7];
        paralist[0] = db.AddParameter("coupon_id", cp.Coupon_id, SqlDbType.Int);
        paralist[1] = db.AddParameter("coupon_name", cp.Coupon_name, SqlDbType.NVarChar, 32);
        paralist[2] = db.AddParameter("coupon_des",cp.Coupon_des,SqlDbType.NVarChar,255);
        paralist[3] = db.AddParameter("discount", cp.Discount, SqlDbType.Int);
        paralist[4] = db.AddParameter("coupon_num", cp.Coupon_num, SqlDbType.Int);
        paralist[5] = db.AddParameter("date_start",cp.Date_start,SqlDbType.DateTime);
        paralist[6] = db.AddParameter("date_end", cp.Date_end, SqlDbType.DateTime);
        return db.executeUpdate("IS_Coupon", paralist);
    }
    public DataTable GetAllCoupon()
    {
        return db.executeSelect("SELECT_COUPON");
    }
    public DataTable getCouponByID(int id)
    {
        SqlParameter[] paralist = new SqlParameter[4];
        paralist[0] = db.AddParameter("coupon_id", id, SqlDbType.Int);
        paralist[1] = db.AddParameter("coupon_name", null, SqlDbType.NVarChar, 32);
        paralist[2] = db.AddParameter("discount",0, SqlDbType.Int);
        paralist[3] = db.AddParameter("coupon_num", 0, SqlDbType.Int);
        return db.executeSelect("SELECT_COUPON", paralist);
    }
    public DataTable getCouponByName(string name)
    {
        SqlParameter[] paralist = new SqlParameter[4];
        paralist[0] = db.AddParameter("coupon_id", 0, SqlDbType.Int);
        paralist[1] = db.AddParameter("coupon_name", name, SqlDbType.NVarChar, 32);
        paralist[2] = db.AddParameter("discount", 0, SqlDbType.Int);
        paralist[3] = db.AddParameter("coupon_num", 0, SqlDbType.Int);
        return db.executeSelect("SELECT_COUPON", paralist);
    }
    public DataTable getCouponByDiscount(int discount)
    {
        SqlParameter[] paralist = new SqlParameter[4];
        paralist[0] = db.AddParameter("coupon_id", 0, SqlDbType.Int);
        paralist[1] = db.AddParameter("coupon_name", null, SqlDbType.NVarChar, 32);
        paralist[2] = db.AddParameter("discount", discount, SqlDbType.Int);
        paralist[3] = db.AddParameter("coupon_num", 0, SqlDbType.Int);
        return db.executeSelect("SELECT_COUPON", paralist);
    }
    public DataTable getCouponByCouponNum(int value)
    {
        SqlParameter[] paralist = new SqlParameter[4];
        paralist[0] = db.AddParameter("coupon_id", 0, SqlDbType.Int);
        paralist[1] = db.AddParameter("coupon_name", null, SqlDbType.NVarChar, 32);
        paralist[2] = db.AddParameter("discount", 0, SqlDbType.Int);
        paralist[3] = db.AddParameter("coupon_num", value, SqlDbType.Int);
        return db.executeSelect("SELECT_COUPON", paralist);
    }
    


}